package cn.hx.text;

import static org.junit.Assert.*;

import java.util.ArrayList;
import java.util.List;

import org.apache.ibatis.session.SqlSession;
import org.junit.Test;

import cn.hx.pojo.User;
import cn.hx.util.MyBatisUtil;

public class Jtxet {

	@Test
	public void test() {
		SqlSession sqlSession=null;
		int count=0;
		sqlSession=MyBatisUtil.createSession();
		count=sqlSession.selectOne("cn.hx.dao.UserMapper.count");
		System.out.println(count);

	}
	
	@Test
	public void updatetest() {
		
		SqlSession sqlSession=null;
		try {
			User user=new User();
			user.setId(5);
			user.setUserName("hh");
			user.setPassWord("273");
			
			
			sqlSession=MyBatisUtil.createSession();
			sqlSession.update("cn.hx.dao.UserMapper.update", user);
			sqlSession.commit();
			
			
			
		} catch (Exception e) {
			// TODO: handle exception
			
		}finally{
			MyBatisUtil.closesqlsession(sqlSession);
		}
		
		
		
		
		
		
		
		
		
		
		
	}
	@Test
	public void deletetest() {
		SqlSession sqlSession=null;
		User user=new User();
		user.setId(4);
		try {
			sqlSession=MyBatisUtil.createSession();
			sqlSession.delete("cn.hx.dao.UserMapper.delete", user);
			sqlSession.commit();
			
			
		} catch (Exception e) {
			// TODO: handle exception
		}finally{
			MyBatisUtil.closesqlsession(sqlSession);
		}
		
		
		
		
	}
	
	@Test
	public void select() {
	SqlSession sqlSession=null;
	try {
		List<User> unsList=new ArrayList<User>();
		sqlSession=new MyBatisUtil().createSession();
		unsList=sqlSession.selectList("cn.hx.dao.UserMapper.getUserList");
		for (User user:unsList) {
			System.out.println(user.getId());
		}
		
		
		
	} catch (Exception e) {
		// TODO: handle exception
	}
			
	
	}
	}


